```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Redis高可用优化指南 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8f9fa;
            color: #333;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #6e48aa 0%, #9d50bb 100%);
            color: white;
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            border-radius: 12px;
            overflow: hidden;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .code-block {
            font-family: 'Courier New', Courier, monospace;
            background-color: #2d3748;
            color: #e2e8f0;
            border-radius: 6px;
            padding: 1rem;
            position: relative;
        }
        .code-block::before {
            content: attr(data-lang);
            position: absolute;
            top: 0;
            right: 0;
            background-color: #4a5568;
            color: #cbd5e0;
            padding: 0.2rem 0.5rem;
            font-size: 0.8rem;
            border-bottom-left-radius: 6px;
        }
        .section-divider {
            position: relative;
            height: 1px;
            background: linear-gradient(90deg, rgba(0,0,0,0) 0%, rgba(110,72,170,0.5) 50%, rgba(0,0,0,0) 100%);
            margin: 3rem 0;
        }
        .section-divider::after {
            content: "⚡";
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            background-color: #f8f9fa;
            padding: 0 1rem;
            color: #6e48aa;
        }
        .feature-icon {
            font-size: 2.5rem;
            margin-bottom: 1rem;
            color: #6e48aa;
            background: linear-gradient(135deg, #6e48aa 0%, #9d50bb 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        .footer {
            background-color: #1a202c;
            color: #e2e8f0;
        }
        .footer a {
            transition: color 0.2s ease;
        }
        .footer a:hover {
            color: #9d50bb;
        }
        .timeline {
            position: relative;
            padding-left: 2rem;
        }
        .timeline::before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            width: 4px;
            background: linear-gradient(to bottom, #6e48aa, #9d50bb);
            border-radius: 2px;
        }
        .timeline-item {
            position: relative;
            padding-bottom: 2rem;
            padding-left: 2rem;
        }
        .timeline-item::before {
            content: '';
            position: absolute;
            left: -1.5rem;
            top: 0;
            width: 1rem;
            height: 1rem;
            border-radius: 50%;
            background-color: #6e48aa;
            border: 3px solid white;
            box-shadow: 0 0 0 3px rgba(110, 72, 170, 0.3);
        }
        .mermaid-container {
            background-color: white;
            padding: 1.5rem;
            border-radius: 12px;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
            margin: 2rem 0;
        }
        .tooltip {
            position: relative;
            display: inline-block;
            border-bottom: 1px dotted #6e48aa;
            cursor: help;
        }
        .tooltip .tooltiptext {
            visibility: hidden;
            width: 200px;
            background-color: #555;
            color: #fff;
            text-align: center;
            border-radius: 6px;
            padding: 5px;
            position: absolute;
            z-index: 1;
            bottom: 125%;
            left: 50%;
            margin-left: -100px;
            opacity: 0;
            transition: opacity 0.3s;
        }
        .tooltip:hover .tooltiptext {
            visibility: visible;
            opacity: 1;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-4xl text-center">
            <div class="inline-block px-4 py-2 bg-white bg-opacity-20 rounded-full mb-6">
                <span class="text-white text-sm font-medium">高性能缓存解决方案</span>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold text-white mb-6 font-serif">Redis 高可用性优化指南</h1>
            <p class="text-xl text-white opacity-90 max-w-2xl mx-auto mb-10">应对服务器崩溃与性能问题的专业解决方案</p>
            <div class="flex justify-center">
                <a href="#content" class="bg-white text-purple-700 hover:bg-purple-50 px-6 py-3 rounded-full font-medium transition duration-300 transform hover:scale-105 shadow-lg">
                    <i class="fas fa-arrow-down mr-2"></i>探索解决方案
                </a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main id="content" class="container mx-auto max-w-5xl px-4 md:px-0 py-16">
        <!-- Introduction -->
        <section class="mb-20">
            <div class="bg-white rounded-xl p-8 shadow-lg">
                <h2 class="text-3xl font-bold mb-6 text-gray-800 font-serif">为什么Redis高可用性如此重要？</h2>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                    <div>
                        <p class="text-gray-700 mb-6">在现代应用架构中，Redis作为高性能缓存和数据存储的核心组件，其稳定性直接关系到整个系统的可用性和用户体验。一次Redis服务器的崩溃可能导致应用性能急剧下降甚至服务中断。</p>
                        <p class="text-gray-700">本指南将带您了解从数据持久化配置到高可用架构设计的全方位优化策略，帮助您构建更加健壮的Redis基础设施，最大程度减少停机时间并提供无缝的用户体验。</p>
                    </div>
                    <div class="mermaid-container">
                        <div class="mermaid">
                            pie
                                title Redis崩溃的影响
                                "应用性能下降" : 45
                                "数据丢失风险" : 30
                                "用户体验受损" : 20
                                "商业损失" : 5
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Section Divider -->
        <div class="section-divider"></div>

        <!-- Data Persistence -->
        <section class="mb-20">
            <div class="flex items-center mb-10">
                <div class="flex-shrink-0 mr-6">
                    <div class="feature-icon">
                        <i class="fas fa-database"></i>
                    </div>
                </div>
                <div>
                    <h2 class="text-3xl font-bold text-gray-800 font-serif">1. 数据持久化配置</h2>
                    <p class="text-gray-600">确保数据安全，减少崩溃时的数据丢失</p>
                </div>
            </div>

            <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                <!-- RDB -->
                <div class="card bg-white p-6 shadow-md">
                    <h3 class="text-xl font-bold mb-4 text-purple-700 flex items-center">
                        <i class="fas fa-camera-retro mr-3"></i> RDB 快照
                    </h3>
                    <p class="text-gray-700 mb-4">RDB 是Redis提供的快照式持久化方式，可以在指定时间间隔生成数据集的二进制快照。</p>
                    <div class="mb-4">
                        <h4 class="font-medium text-gray-800 mb-2">配置建议：</h4>
                        <div class="code-block" data-lang="redis.conf">
                            save 60 1000  # 每60秒内至少有1000个键被修改时保存<br>
                            dbfilename dump.rdb<br>
                            dir /var/lib/redis
                        </div>
                    </div>
                    <div class="bg-blue-50 p-4 rounded-lg border border-blue-100">
                        <h4 class="font-medium text-blue-800 mb-2 flex items-center">
                            <i class="fas fa-lightbulb mr-2"></i> 专家建议
                        </h4>
                        <p class="text-blue-700 text-sm">在频繁写入场景下，建议缩短保存间隔但不要过于频繁(如每5分钟)，避免过度消耗I/O资源。</p>
                    </div>
                </div>

                <!-- AOF -->
                <div class="card bg-white p-6 shadow-md">
                    <h3 class="text-xl font-bold mb-4 text-purple-700 flex items-center">
                        <i class="fas fa-file-alt mr-3"></i> AOF (Append Only File)
                    </h3>
                    <p class="text-gray-700 mb-4">AOF 记录每个写操作日志，提供更精细的数据恢复能力，但文件体积通常更大。</p>
                    <div class="mb-4">
                        <h4 class="font-medium text-gray-800 mb-2">配置建议：</h4>
                        <div class="code-block" data-lang="redis.conf">
                            appendonly yes<br>
                            appendfsync everysec  # 平衡性能与数据安全<br>
                            auto-aof-rewrite-percentage 100<br>
                            auto-aof-rewrite-min-size 64mb
                        </div>
                    </div>
                    <div class="bg-yellow-50 p-4 rounded-lg border border-yellow-100">
                        <h4 class="font-medium text-yellow-800 mb-2 flex items-center">
                            <i class="fas fa-exclamation-triangle mr-2"></i> 注意事项
                        </h4>
                        <p class="text-yellow-700 text-sm">AOF文件会随时间增长，需要定期重写。在生产环境中，建议同时启用RDB和AOF以获得最佳数据安全性。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- System Resource Management -->
        <section class="mb-20">
            <div class="flex items-center mb-10">
                <div class="flex-shrink-0 mr-6">
                    <div class="feature-icon">
                        <i class="fas fa-server"></i>
                    </div>
                </div>
                <div>
                    <h2 class="text-3xl font-bold text-gray-800 font-serif">2. 系统资源管理</h2>
                    <p class="text-gray-600">优化内存与磁盘I/O，预防性能瓶颈</p>
                </div>
            </div>

            <div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-10">
                <!-- Memory Management -->
                <div class="card bg-white p-6 shadow-md">
                    <h3 class="text-xl font-bold mb-4 text-purple-700 flex items-center">
                        <i class="fas fa-memory mr-3"></i> 内存管理
                    </h3>
                    <p class="text-gray-700 mb-4">合理配置Redis内存使用策略，避免OOM(内存不足)错误导致的崩溃。</p>
                    <div class="mb-4">
                        <div class="code-block" data-lang="redis.conf">
                            maxmemory 2gb  # 根据实际情况调整<br>
                            maxmemory-policy allkeys-lru  # 内存满时的淘汰策略<br>
                            hz 10  # 调整后台任务执行频率
                        </div>
                    </div>
                    <div class="bg-purple-50 p-4 rounded-lg border border-purple-100">
                        <h4 class="font-medium text-purple-800 mb-2 flex items-center">
                            <i class="fas fa-chart-line mr-2"></i> 监控建议
                        </h4>
                        <p class="text-purple-700 text-sm">使用<code>INFO memory</code>命令定期监控内存使用情况，关注used_memory和used_memory_rss指标。</p>
                    </div>
                </div>

                <!-- Disk I/O -->
                <div class="card bg-white p-6 shadow-md">
                    <h3 class="text-xl font-bold mb-4 text-purple-700 flex items-center">
                        <i class="fas fa-hdd mr-3"></i> 磁盘 I/O 优化
                    </h3>
                    <p class="text-gray-700 mb-4">Redis持久化性能高度依赖磁盘I/O能力，优化I/O可显著提升整体性能。</p>
                    <ul class="list-disc pl-5 text-gray-700 mb-4 space-y-2">
                        <li>使用SSD而非HDD存储数据</li>
                        <li>为Redis分配独立的磁盘或分区</li>
                        <li>禁用透明大页(THP)以减少延迟</li>
                        <li>监控磁盘健康状态，预防故障</li>
                    </ul>
                    <div class="code-block" data-lang="bash">
                        # 禁用透明大页<br>
                        echo never > /sys/kernel/mm/transparent_hugepage/enabled
                    </div>
                </div>
            </div>

            <!-- Resource Monitoring Timeline -->
            <div class="bg-white rounded-xl p-6 shadow-lg">
                <h3 class="text-xl font-bold mb-6 text-gray-800 flex items-center">
                    <i class="fas fa-clock mr-3 text-purple-700"></i> 资源监控时间线
                </h3>
                <div class="timeline">
                    <div class="timeline-item">
                        <h4 class="font-bold text-gray-800 mb-2">每日检查</h4>
                        <p class="text-gray-700">检查内存使用率、命中率、连接数等关键指标</p>
                    </div>
                    <div class="timeline-item">
                        <h4 class="font-bold text-gray-800 mb-2">每周任务</h4>
                        <p class="text-gray-700">分析慢查询日志，评估AOF重写频率</p>
                    </div>
                    <div class="timeline-item">
                        <h4 class="font-bold text-gray-800 mb-2">每月维护</h4>
                        <p class="text-gray-700">检查磁盘健康状况，评估容量规划</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Section Divider -->
        <div class="section-divider"></div>

        <!-- High Availability -->
        <section class="mb-20">
            <div class="flex items-center mb-10">
                <div class="flex-shrink-0 mr-6">
                    <div class="feature-icon">
                        <i class="fas fa-shield-alt"></i>
                    </div>
                </div>
                <div>
                    <h2 class="text-3xl font-bold text-gray-800 font-serif">3. 高可用性和灾备方案</h2>
                    <p class="text-gray-600">构建冗余架构，确保业务连续性</p>
                </div>
            </div>

            <div class="mermaid-container mb-10">
                <div class="mermaid">
                    graph TD
                        A[客户端] --> B[Redis主节点]
                        B -->|同步| C[Redis从节点1]
                        B -->|同步| D[Redis从节点2]
                        E[Sentinel集群] -->|监控| B
                        E -->|故障转移| C
                        E -->|监控| C
                        E -->|监控| D
                </div>
            </div>

            <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                <!-- Master-Slave -->
                <div class="card bg-white p-6 shadow-md">
                    <h3 class="text-xl font-bold mb-4 text-purple-700 flex items-center">
                        <i class="fas fa-copy mr-3"></i> 主从复制
                    </h3>
                    <p class="text-gray-700 mb-4">基本的高可用方案，主节点处理写操作，从节点提供读服务和数据备份。</p>
                    <div class="code-block" data-lang="redis.conf">
                        # 从节点配置<br>
                        replicaof &lt;master-ip&gt; &lt;master-port&gt;<br>
                        replica-read-only yes
                    </div>
                </div>

                <!-- Sentinel -->
                <div class="card bg-white p-6 shadow-md">
                    <h3 class="text-xl font-bold mb-4 text-purple-700 flex items-center">
                        <i class="fas fa-bell mr-3"></i> Redis Sentinel
                    </h3>
                    <p class="text-gray-700 mb-4">哨兵系统监控Redis实例，自动进行故障检测和转移。</p>
                    <div class="code-block" data-lang="sentinel.conf">
                        sentinel monitor mymaster &lt;ip&gt; 6379 2<br>
                        sentinel down-after-milliseconds mymaster 5000<br>
                        sentinel failover-timeout mymaster 60000
                    </div>
                </div>

                <!-- Cluster -->
                <div class="card bg-white p-6 shadow-md">
                    <h3 class="text-xl font-bold mb-4 text-purple-700 flex items-center">
                        <i class="fas fa-network-wired mr-3"></i> 集群模式
                    </h3>
                    <p class="text-gray-700 mb-4">分布式解决方案，数据自动分片，支持水平扩展。</p>
                    <div class="code-block" data-lang="bash">
                        # 创建集群<br>
                        redis-cli --cluster create \<br>
                        node1:7000 node2:7000 node3:7000 \<br>
                        --cluster-replicas 1
                    </div>
                </div>
            </div>
        </section>

        <!-- Monitoring and Security -->
        <section class="mb-20">
            <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                <!-- Monitoring -->
                <div class="card bg-white p-6 shadow-md">
                    <div class="flex items-center mb-6">
                        <div class="flex-shrink-0 mr-4">
                            <div class="feature-icon">
                                <i class="fas fa-chart-pie"></i>
                            </div>
                        </div>
                        <div>
                            <h3 class="text-2xl font-bold text-gray-800 font-serif">4. 监控和预警</h3>
                            <p class="text-gray-600">实时掌握Redis健康状况</p>
                        </div>
                    </div>
                    <div class="space-y-4">
                        <div>
                            <h4 class="font-bold text-gray-800 mb-2">关键监控指标：</h4>
                            <ul class="list-disc pl-5 text-gray-700 space-y-1">
                                <li>内存使用率 (<span class="tooltip">used_memory<span class="tooltiptext">Redis分配器分配的总内存</span></span>)</li>
                                <li>命中率 (<span class="tooltip">keyspace_hits/keyspace_misses<span class="tooltiptext">缓存命中与未命中比例</span></span>)</li>
                                <li>连接数 (<span class="tooltip">connected_clients<span class="tooltiptext">当前客户端连接数量</span></span>)</li>
                                <li>延迟 (<span class="tooltip">latency<span class="tooltiptext">命令执行延迟统计</span></span>)</li>
                            </ul>
                        </div>
                        <div>
                            <h4 class="font-bold text-gray-800 mb-2">推荐工具：</h4>
                            <div class="flex flex-wrap gap-2">
                                <span class="bg-gray-100 px-3 py-1 rounded-full text-sm">Redis-cli INFO</span>
                                <span class="bg-gray-100 px-3 py-1 rounded-full text-sm">Prometheus</span>
                                <span class="bg-gray-100 px-3 py-1 rounded-full text-sm">Grafana</span>
                                <span class="bg-gray-100 px-3 py-1 rounded-full text-sm">RedisStat</span>
                                <span class="bg-gray-100 px-3 py-1 rounded-full text-sm">New Relic</span>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Security -->
                <div class="card bg-white p-6 shadow-md">
                    <div class="flex items-center mb-6">
                        <div class="flex-shrink-0 mr-4">
                            <div class="feature-icon">
                                <i class="fas fa-lock"></i>
                            </div>
                        </div>
                        <div>
                            <h3 class="text-2xl font-bold text-gray-800 font-serif">5. 安全性</h3>
                            <p class="text-gray-600">保护Redis免受未授权访问</p>
                        </div>
                    </div>
                    <div class="space-y-4">
                        <div>
                            <h4 class="font-bold text-gray-800 mb-2">基本安全措施：</h4>
                            <ul class="list-disc pl-5 text-gray-700 space-y-1">
                                <li>设置强密码 (requirepass)</li>
                                <li>限制绑定IP (bind 127.0.0.1)</li>
                                <li>禁用危险命令 (rename-command)</li>
                                <li>使用防火墙限制访问</li>
                            </ul>
                        </div>
                        <div class="code-block" data-lang="redis.conf">
                            requirepass YourStrongPassword123!<br>
                            bind 127.0.0.1<br>
                            rename-command FLUSHALL ""<br>
                            rename-command CONFIG ""
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Summary -->
        <section class="bg-purple-50 rounded-xl p-8 shadow-lg mb-20">
            <h2 class="text-3xl font-bold mb-6 text-purple-800 text-center font-serif">Redis高可用性优化总结</h2>
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                <div class="bg-white p-5 rounded-lg shadow-sm">
                    <div class="text-purple-600 mb-3">
                        <i class="fas fa-check-circle text-2xl"></i>
                    </div>
                    <h4 class="font-bold text-gray-800 mb-2">持久化策略</h4>
                    <p class="text-gray-700 text-sm">结合使用RDB和AOF，定期测试备份恢复流程</p>
                </div>
                <div class="bg-white p-5 rounded-lg shadow-sm">
                    <div class="text-purple-600 mb-3">
                        <i class="fas fa-server text-2xl"></i>
                    </div>
                    <h4 class="font-bold text-gray-800 mb-2">资源管理</h4>
                    <p class="text-gray-700 text-sm">监控内存和磁盘使用，设置合理限制和淘汰策略</p>
                </div>
                <div class="bg-white p-5 rounded-lg shadow-sm">
                    <div class="text-purple-600 mb-3">
                        <i class="fas fa-shield-alt text-2xl"></i>
                    </div>
                    <h4 class="font-bold text-gray-800 mb-2">高可用架构</h4>
                    <p class="text-gray-700 text-sm">根据业务需求选择主从、哨兵或集群方案</p>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="footer py-12 px-4">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col items-center text-center">
                <div class="text-2xl font-bold text-white mb-4">技术小馆</div>
                <div class="text-gray-300 mb-6">专业的开发者知识分享平台</div>
                <a href="http://www.yuque.com/jtostring" class="text-white hover:text-purple-300 transition duration-300">
                    <i class="fas fa-external-link-alt mr-2"></i>访问我们的语雀空间
                </a>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```